#pragma once
#include <list>
#include <string>
#include <string.h>

#ifndef __FIELDCOPY__
#ifdef WIN32
#define __FIELDCOPY__(field,dest)	strncpy_s(field,_countof(field),dest,_TRUNCATE)
#else
#define __FIELDCOPY__(field,dest)	strcpy(field, dest)
#endif
#endif

typedef	unsigned int UINT;

#ifndef PRICE_LEN
#define PRICE_LEN 8
#endif
#ifndef VOLUME_LEN
#define VOLUME_LEN 10
#endif

//E_FID_QB_MM_EX_PRICE_QUERY_V2 = 50385,			// 货币市场,查询交易所实时行情，吴响，原50230
//-----------------------------------------------------------------------------------by scofined.qi
typedef char    tMmPrice[PRICE_LEN];	// 价格
typedef char	tMmVolume[VOLUME_LEN];
typedef char	tMmKey[32 + 1];			// Key 
typedef char	tMmId[32];				// id
typedef char    tMmMarket[8];			// 市场，CIB，SSE，SZE
//Req
class xMMReq_c
{
public:
	tMmKey			m_RateKey;			//Key			
	tMmId			m_RateID;			//ID
	tMmMarket		m_ListedMarket;		//市场，CIB，SSE，SZE
	xMMReq_c() {
		memset(m_RateKey, 0, sizeof(m_RateKey));
		memset(m_RateID, 0, sizeof(m_RateID));
		memset(m_ListedMarket, 0, sizeof(m_ListedMarket));
	}
};
class xxMMListQuery_c
{
public:
	std::list<xMMReq_c> m_List;										//,存款及再贷款 list
};
//Ack
class xMMPrice_c
{
public:
	tMmKey			m_RateKey;			//rk Key	
	tMmMarket		m_ListedMarket;		//lm 市场，CIB，SSE，SZE
	tMmPrice		m_Price;			//pri 最新价
	tMmPrice		m_Chg;				//chg 变动价格
	tMmPrice		m_Open;				//op 开盘价格
	tMmPrice		m_High;				//hp 最高价格
	tMmPrice		m_Low;				//lp 最低价格
	tMmPrice		m_Prev;				//pc 昨收
	tMmVolume		m_Vol;				//vol 成交量
	tMmPrice		m_Weight;			//wgt 加权
	time_t			m_Time;				//tm 行情时间
	xMMPrice_c() :m_Time(0)
	{
		memset(m_RateKey, 0, sizeof(m_RateKey));
		memset(m_ListedMarket, 0, sizeof(m_ListedMarket));
		memset(m_Price, 0, sizeof(m_Price));
		memset(m_Chg, 0, sizeof(m_Chg));
		memset(m_Open, 0, sizeof(m_Open));
		memset(m_High, 0, sizeof(m_High));
		memset(m_Low, 0, sizeof(m_Low));
		memset(m_Prev, 0, sizeof(m_Prev));
		memset(m_Prev, 0, sizeof(m_Prev));
		memset(m_Vol, 0, sizeof(m_Vol));
		memset(m_Weight, 0, sizeof(m_Weight));
	}
};
class xxMMListAck_c
{
public:
	std::list<xMMPrice_c> m_List;										//行情列表
};
//交易所回购
//E_FID_QB_EXCHANGE_REPO_PRICE_REQ			= 50700,		    //交易所回购周年化加权请求，请求返回
//Req
struct xQBExchangeRepoReq_t {
	char		m_UserId[32 + 1];			// 用户id
	xQBExchangeRepoReq_t()
	{
		memset(this, 0, sizeof(xQBExchangeRepoReq_t));
	}
};
//交易所回购
struct xQBExchangeRepoUnit_c
{
	char  m_SecurityID[8];				    //回购ID
	char  m_WeightedAnnualRate[12];			//周年化加权     
	xQBExchangeRepoUnit_c()
	{
		memset(this, 0, sizeof(xQBExchangeRepoUnit_c));
	}
};
//Ack
class xQBExchangeRepoListAck_c
{
public:
	std::list<xQBExchangeRepoUnit_c>    m_List;   //交易所回购
};

//-----------------------------------------------------------------------------------
//E_FID_QBA_PUBLIC_OPTION_V2_REQ				= 50402,			// 固收综合屏 债券首页的公开市场操作-Req
struct QBAPublicOptionReq {								//客户端以周为单位请求						
	UINT m_beginDate;
	UINT m_endDate;
};

//Ack
//净投放/净回笼 计算因子
struct QBAPubOptNetInvFactor
{
	int  id;				//key
	int  order;				//排序
	int  dft;				//是否默认
	std::string name;		//显示名
	std::string name_en;	//英文名
	double value;			//今日
	double weekValue;		//本周
	double monthValue;		//本月
	QBAPubOptNetInvFactor() :id(0), order(0), dft(0), value(0), weekValue(0), monthValue(0) {};
};

class xQBAPublicOptionUnit_c
{
public:
	UINT		m_Date;												//日期
	char		m_Type[64];											//方式
	char		m_Type_En[64];										//方式_英文
	char		m_TermType[32];										//期限品种
	char		m_TermType_En[32];									//期限品种_英文
	double		m_Rate;												//招标利率
	double		m_Money;											//回笼资金

	bool operator<(const xQBAPublicOptionUnit_c& that) const
	{
		return m_Date < that.m_Date;
	}
	xQBAPublicOptionUnit_c()
	{
		memset(this, 0, sizeof(xQBAPublicOptionUnit_c));
	}
};

class xQBAPublicOptionListV2_c
{
public:
	std::list<xQBAPublicOptionUnit_c> m_List;			//新增或更新
	std::list<xQBAPublicOptionUnit_c> m_DelList;		//需删除的投放
	std::list<QBAPubOptNetInvFactor> m_NetInvList;		//统计量
	xQBAPublicOptionListV2_c() {}
};

//E_FID_QBA_PUBLIC_OPTION_V2_PUSH = 50403,			// 固收综合屏 债券首页的公开市场操作-推送
//Req-NULL
//Ack 同50402

//-------------------------------------------------------------------------------------
//E_FID_CIB_REPO_REQ							= 50828,			//请求，银行间回购请求
//Req
struct xQbCibRepoReq_c
{
public:
	//Date
	uint32_t m_Date;	//日期：20190905
	xQbCibRepoReq_c() :m_Date(0) {};
};
//Ack
struct xQbCibRepo_c
{
	//ID
	char m_szID[32 + 1];		//期限,DR001?需要商榷
	//Rate
	double m_dRate;				//利率
	//Diff
	double m_dDiff;				//变化
	//UpdateTime				
	time_t m_tUpdateTime;			//更新时间

	xQbCibRepo_c()
	{
		memset(this, 0, sizeof(*this));
	}
	xQbCibRepo_c(char* pId, double dRate, double dDiff, time_t tUpdateTime)
	{
		__FIELDCOPY__(m_szID, pId);
		m_dRate = dRate;
		m_dDiff = dDiff;
		m_tUpdateTime = tUpdateTime;
	}
};
struct xQbCibRepoAck_c
{
	//List
	std::list<xQbCibRepo_c> m_List;
};

//-----------------------------------------------------------------------------------
//E_FID_QB_SHIBOR_QUERY						= 50220,			// 基准利率,查询Shibor
//无请求包体，应答结构如下
class xBaseUnit_c
{
public:
	char		m_term[32];			//期限	
	char		m_gjk_code[16];		//基准利率的GJK code 
	char		m_gjk_code_en[32];	//基准利率的GJK code - 英文
	double		m_rate;				//利率
	double		m_change;			//变化
	UINT		m_date;				//日期
	bool operator<(const xBaseUnit_c& unit) const
	{
		return m_date < unit.m_date;
	}
	xBaseUnit_c()
		:m_rate(0)
		, m_change(0)
		, m_date(0)
	{
		memset(m_term, 0, sizeof(m_term));
		memset(m_gjk_code, 0, sizeof(m_gjk_code));
		memset(m_gjk_code_en, 0, sizeof(m_gjk_code_en));
	}
	xBaseUnit_c(char* pTerm, char* pCode, char* pCodeEn, double dRate, double dChange)
	{
		__FIELDCOPY__(m_term, pTerm);
		__FIELDCOPY__(m_gjk_code, pCode);
		__FIELDCOPY__(m_gjk_code_en, pCodeEn);

		m_rate = dRate;
		m_change = dChange;
		m_date = 0;
	}
};

class xShiborList_c
{
public:
	std::list<xBaseUnit_c> m_List;									//Shibor list
};

//E_FID_QB_SHIBOR_PUSH = 50832,			// 基准利率,查询Shibor
//req:NULL
//ack:xShiborList_c

//E_FID_QB_SHIBOR_PUSH_CANCEL = 50833,			// 基准利率,查询Shibor
//req:NULL
//ack:NULL

//-----------------------------------------------------------------------------------
//E_FID_QB_FIXIN_REPO_RATE_QUERY				= 50221,			// 基准利率,查询回购定盘利率
//无请求包体，应答同50220
typedef xShiborList_c xFixingRepoRateList_c;

//E_FID_QB_FIXIN_REPO_RATE_PUSH = 50388,			// 基准利率,推送回购定盘利率
//请求应答同50221

//E_FID_QB_FIXIN_DEPO_REPO_RATE_QUERY	= 50287,			// 基准利率,查询银银间回购定盘利率,QB3.8新增
//无请求包体，应答同50220
typedef xShiborList_c xFixingDepoRepoRateList_c;

//E_FID_QB_FIXIN_DEPO_REPO_RATE_PUSH = 50400,			// 基准利率,推送银银间回购定盘利率,QB3.8新增 
//请求应答同50287

//-----------------------------------------------------------------------------------
//E_FID_QB_LPR_QUERY							= 50222,			// 基准利率,查询LPR,贷款利率
//无请求包体，应答同50220
//typedef xShiborList_c xLPRList_c;

//-----------------------------------------------------------------------------------
// E_FID_QB_SHIBOR_HIS_QUERY					= 50223,			// 基准利率,查询Shibor 历史
// 请求
// class xShiborHisQuery_c//req
// {
// public:
// 	tSbGjkCode		m_gjk_code;											//期限	
// 	xShiborHisQuery_c()
// 	{
// 		memset(m_gjk_code, 0, sizeof(m_gjk_code));
// 	}
// };
// 应答同50220
// typedef xShiborList_c xShiborHisList_c;

//-----------------------------------------------------------------------------------
//E_FID_QB_REPO_AVG_QUERY						= 50224,			// 基准利率,查询回购平均
//无请求包体，应答同50220
// typedef xShiborList_c xRepoAvgList_c;
